import java.util.Arrays;
import java.util.EmptyStackException;
public class MyStack {
    public int[] elem;
    public int usedSize;

    public MyStack(){
        this.elem = new int[10];
    }

    public void push(int val){
        if(isFull()){
           this.elem = Arrays.copyOf(elem,elem.length*2);
        }
        elem[usedSize] = val;
        usedSize++;
    }

    public boolean isFull(){
        return usedSize==elem.length;
    }
    //获取栈顶元素但不删除
    public int pop(){
        if(isEmpty()){
            throw new EmptyStackException();//不太会的异常
        }
        return elem[usedSize-1];
    }
    public boolean isEmpty(){
        return usedSize==0;
    }
}
